<template>
	<view class="serve">
		<view class="nav">
			<u-tabs :list="list1" lineColor="#FF5B1A" :activeStyle="{color: '#FF5B1A'}" @click="change" :scrollable="false"></u-tabs>
		</view>
		<scroll-view scroll-y="true" class="main" @scrolltolower="lower()">
			<view class="list" v-for="(item,index) of list">
				<image :src="oss(item.user.avatar)" class="cover" mode=""></image>
				<view class="info">
					<view class="title">
						<view class="l">{{item.user.nickname}}</view>
						<view class="r" v-if="type === 0">待付款</view>
						<view class="r" v-if="type === 1">已付款</view>
						<view class="r" v-if="type === 2">已完成</view>
						<view class="r" v-if="type === -1">申请退款</view>
						<view class="r" v-if="type === -2">已退款</view>
					</view>
					
					<view class="num">
						<view class="l">
							<text class="type">服务项目</text>
							<view class="word">{{item.name}}</view>
						</view>
						<view class="r"><text class="icon">¥</text>{{item.price}}</view>
					</view>
					<view class="other">
						<view class="l"  @click="tel(item.user.mobile)">联系雇主</view>
						<view class="r" v-if="type === 0" @click="changeprice(item.id)">修改价格</view>
						<view class="r btn" v-if="type === -1" @click="agree(item.id)">同意</view>
						<view class="r btn" v-if="type === -1" @click="refund(item.id)">拒绝</view>
					</view>
				</view>
			</view>
			<u-empty v-if="finish && list.length === 0" :marginTop="200">
			</u-empty>
			
		</scroll-view>
		<u-modal :show="show"  :title="title" @confirm="confirm" @cancel="show = false" :showCancelButton="true">
					<view class="slot-content">
						  <u--input
						    placeholder="请输入新价格"
						    border="surround"
						    v-model="price"
						  ></u--input>
					</view>
				</u-modal>
				<u-modal :show="show1"  title="确定同意退款吗？" @confirm="confirm1" @cancel="show1 = false" :showCancelButton="true"></u-modal>
				<u-modal :show="show2"  title="确定拒绝退款吗？" @confirm="confirm2" @cancel="show2 = false" :showCancelButton="true"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [{
					name: '待付款',
					type: 0
				}, {
					name: '已付款',
					type: 1
				}, {
					name: '已完成',
					type: 2
				}, {
					name: '退款中',
					type: -1
				}, {
					name: '已退款',
					type: -2
				}],
				page: 1,
				finish: false,
				type: 0,
				list: [],
				show: false,
				price: '',
				id: '',
				title: '修改价格',
				show1: false,
				 show2: false,
			};
		},
		onLoad() {
			this.getList()
		},
		methods: {
			agree(id) {
				this.show1 = true
				this.id = id
			},
			refund(id) {
				this.show2 = true
				this.id = id
			},
			confirm1() {
					this.show1 = false
					uni.$u.http.post('/userservice', {
						types: 'refund',
						id: this.id
					}).then(res => {
						if (res.code == 1) {
							uni.$u.toast(res.msg)
							this.reload()
						}
					}).catch((res) => {
							
					})
			},
			confirm2() {
					this.show2 = false
					uni.$u.http.post('/userservice', {
						types: 'refuse',
						id: this.id
					}).then(res => {
						if (res.code == 1) {
							uni.$u.toast(res.msg)
							this.reload()
						}
					}).catch((res) => {
							
					})
			},
			changeprice(id) {
				this.show = true
				this.id= id
			},
			confirm() {
					this.show = false
					uni.$u.http.post('/userservice', {
						types: 'editprice',
						id: this.id,
						price: this.price
					}).then(res => {
						if (res.code == 1) {
							uni.$u.toast(res.msg)
							this.reload()
						}
					}).catch((res) => {
							
					})
			},
			tel(mobile) {
				uni.$u.http.post('/mobilelog',{
					mobile
				}).then(res => {
					if (res.code == 1) {
						uni.makePhoneCall({
							phoneNumber: mobile
						});
					}
				}).catch((res) => {
				
				})
			},
			change(e) {
				console.log(e)
				this.type = e.type
				this.reload()
			},
			reload() {
				this.page = 1
				this.finish = false
				this.list = []
				this.getList()
			},
			lower() {
				this.page++
				this.getList()
			},
			getList() {
				if (this.finish) {
					return
				}
				uni.$u.http.post('/userservice', {
					page: this.page,
					type: this.type
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {
		
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		background: #f6f6f6;
	}
	.serve{
		height: 100%;
		position: relative;
	}
	.nav{
		display: flex;
		align-items: center;
		justify-content: center;
		height: 90rpx;
	}
.main{
	position: absolute;
	left: 0;
	width: 100%;
	bottom: 0;
	top: 90rpx;
	.list{
		display: flex;
		margin: 0 20rpx 20rpx;
		padding: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;
		position: relative;
		.cover{
			width: 170rpx;
			height: 170rpx;
			margin-right: 20rpx;
			flex-direction: 0;
			border-radius: 10rpx;
		}
		.address{
			font-size: 25rpx;
			color: #575859;
			margin: 10rpx 0 20rpx;
		}
		
		.info{
			flex: 1;
			.title{
				display: flex;
				align-items: center;
				.l{
					flex: 1;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-weight: bold;
				}
				.r{
					color: #428DFC;
					font-size: 24rpx;
					flex-shrink: 0;
					display: flex;
					align-items: center;
				}
			}
			.other{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.l{
					font-size: 28rpx;
					color: #333;
				}
				.r{
					font-size: 28rpx;
					color: #333;
				}
				.btn{
					padding: 2rpx 8rpx;
					border: 1px solid #FF8007;
					color: #FF8007;
					border-radius: 4rpx;
					font-size: 24rpx;
				}
			}
			.num{
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 20rpx 0;
				.l{
					display: flex;
					align-items: center;
					.type{
						color: #999999;
						font-size: 24rpx;
					}
					.word{
						background-color: #FFFAE5;
						height: 36rpx;
						border-radius: 18rpx;
						color: #FF8007;
						font-size: 20rpx;
						padding: 0 20rpx;
						display: flex;
						align-items: center;
					}
				}
				.r{
					color: #FF5B1A;
					font-size: 40rpx;
					.icon{
						font-size: 28rpx;
					}
				}
			}
		}
	}
}
</style>
